﻿CREATE PROCEDURE [steve].[spSteve_UpdateContent]
	@ContentId uniqueidentifier,
	@Path varchar(255),
	@SiteUrlId uniqueidentifier,
	@Title nvarchar(200),
	@Teaser nvarchar(4000),
	@ThumbnailContentId uniqueidentifier,
	@PublicationDate datetime2(7),
	@PublisherUrlId uniqueidentifier,
	@Publisher nvarchar(200),
	@Author nvarchar(200),
	@Height int,
	@Width int,
	@MimeType varchar(50),
	@MimeSubtype varchar(50),
	@ContentDataId uniqueidentifier,
	
	@RevisionDate datetime2(7),
	@RevisionMembershipId uniqueidentifier,
	@RevisionComment nvarchar(400)
	
AS
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;
	
	DECLARE @revision INT, @error int
	
	SELECT @revision = MAX(RevisionNumber) + 1
	FROM ContentRevision
	WHERE ContentId = @ContentId

	select @error = @@error
	if @error <> 0 return @error

	insert into ContentRevision (
		ContentId,
		RevisionNumber,
		Title,
		Teaser,
		ThumbnailContentId,
		PublicationDate,
		PublisherUrlId,
		Publisher,
		Author,
		Height,
		Width,
		MimeType,
		MimeSubtype,
		ContentDataId,
		RevisionComment,
		RevisionDate,
		RevisionMembershipId)
	values (
		@ContentId,
		@revision,
		@Title,
		@Teaser,
		@ThumbnailContentId,
		@PublicationDate,
		@PublisherUrlId,
		@Publisher,
		@Author,
		@Height,
		@Width,
		@MimeType,
		@MimeSubtype,
		@ContentDataId,
		@RevisionComment,
		@RevisionDate,
		@RevisionMembershipId)

	select @error = @@error
	if @error <> 0 return @error

	UPDATE Content
	SET LatestRevisionNumber = @revision
		, [Path] = @Path
		, SiteUrlId = @SiteUrlId
	WHERE ContentId = @ContentId

	select @error = @@error
	if @error <> 0 return @error
	
	SELECT @revision as LatestRevisionNumber


RETURN 0